from django.utils.deprecation import MiddlewareMixin
from django.db.models import F
from jilu.models import Count

class MD1(MiddlewareMixin):

    def process_request(self, request):
        print('----MD1----process_request----', id(request))
        # Count.objects.filter(id=1).update(count=F('count')+1)

        if "HTTP_X_FORWARDED_FOR" in request.META:
            user_ip = request.META["HTTP_X_FORWARDED_FOR"]
        else:
            user_ip = request.META["REMOTE_ADDR"]
        print(user_ip)
        if user_ip != user_ip:
            Count.objects.filter(id=1).update(count=F('count')+1)

    def process_view(self, request, view_func, view_arges, view_kwarges):
        print('----MD1----process_view----', id(request))

    def process_response(self, request, response):
        print('----MD1----process_response----', id(request))
        return response

    def process_exception(self, request, exception):
        print('-----MD1-----process_exception-----', id(request))

